\begin{algorithm}[!hpbt]
\caption{ Adaptive pre-writeback algorithm}\label{alg2}
\begin{algorithmic}[1]
\Require
Backup warning threshold $B_{th}$

\Ensure
Pre-writeback decision 

\State Initial average power on-time $T_{on} \gets 0$, average task processing time $T_{proc} \gets 0$

\If {A task is finished}
\State Getting the task processing time $T_{proc-last}$
\State $T_{proc} = \alpha T_{proc-last} + (1-\alpha) T_{proc}$, where $\alpha$ is a weight factor
\EndIf

\If {A passive power down occurs}
\State Getting the last power-on time $T_{on-last}$
\State $T_{on} = \beta T_{on-last} + (1-\beta) T_{on}$, where $\beta$ is a weight factor
\State Entering into the partial backup state
\EndIf

\If {The backup warning threshold $B_{th}$ is reached}
\If {$T_{proc}>T_{on}$}
\State Executing the pre-wirteback process
\EndIf
\EndIf

%\For {j=1 to M}
%\If {$R_j>D_{th}$}
% \ForAll{Cache lines $C_i$}
%\If {$C_i \to RUB == j$}
%\State $C_i \to S = 1$
%\EndIf
%%\EndIf
%\EndFor
%\EndIf
%\EndFor


\end{algorithmic}
\end{algorithm}

